package com.teama4.shop.service;

import com.teama4.shop.domain.Orders;
import com.teama4.shop.domain.OrdersExample;
import com.teama4.shop.mapper.OrdersMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service
public class OrdersServiceImpl implements OrdersService {
    @Autowired
    private OrdersMapper ordersMapper;
    @Override
    public long countByExample(OrdersExample example) {
        return ordersMapper.countByExample(example);
    }

    @Override
    public int deleteByExample(OrdersExample example) {
        return ordersMapper.deleteByExample(example);
    }

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return ordersMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(Orders record) {
        return ordersMapper.insert(record);
    }

    @Override
    public int insertSelective(Orders record) {
        return ordersMapper.insertSelective(record);
    }

    @Override
    public List<Orders> selectByExample(OrdersExample example) {
        return ordersMapper.selectByExample(example);
    }

    @Override
    public Orders selectByPrimaryKey(Integer id) {
        return ordersMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByExampleSelective(Orders record, OrdersExample example) {
        return ordersMapper.updateByExampleSelective(record,example);
    }

    @Override
    public int updateByExample(Orders record, OrdersExample example) {
        return ordersMapper.updateByExample(record,example);
    }

    @Override
    public int updateByPrimaryKeySelective(Orders record) {
        return ordersMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Orders record) {
        return ordersMapper.updateByPrimaryKey(record);
    }

    @Override
    public int saveOrder(Orders orders) {
        if(orders.getId()==null) {
            Integer serviceId = UUID.randomUUID().toString().hashCode();
            if (serviceId < 0) {//有可能是负数
                serviceId = -serviceId;
            }
            orders.setId(serviceId);
            return ordersMapper.insert(orders);
        } else {
            return ordersMapper.updateByPrimaryKey(orders);
        }
    }

    @Override
    public int updateOrderStatus(int id) {
        return ordersMapper.updateOrderStatus(id);
    }
}
